module GYLite
{
												
			
	export class GYTitleWindow extends GYSkinContainer
	{
		private _canDrag:boolean;
		private _dragRange:number;
		private _tempX:number;
		private _tempY:number;
		public constructor(s:any=null)
		{
			super();			
			this.skin = s;
			this.initComponent();
		}
		protected initComponent():void
		{var s = this;
			s.closeBtn.setOnClick(s.oper,s);
			s._dragRange = 40;
		}
		private dragDown(e:egret.TouchEvent):void
		{var s = this;
			if(s.mouseY < s._dragRange)
			{
				GYSprite.$stage.addEventListener(egret.TouchEvent.TOUCH_END, s.dragUp,s);
				CommonUtil.addStageLoop(s.dragLoop,s);
				s._tempX = s.x - GYSprite.stageX;
				s._tempY = s.y - GYSprite.stageY;
				// s.startDrag();
			}
		}
		private dragUp(e:egret.TouchEvent):void
		{var s = this;
			GYSprite.$stage.removeEventListener(egret.TouchEvent.TOUCH_END, s.dragUp,s);
			CommonUtil.delStageLoop(s.dragLoop,s);
			// s.stopDrag();
		}
		private dragLoop(t:number):void
		{var s = this;
			s.x = GYSprite.stageX + s._tempX;
			s.y = GYSprite.stageY + s._tempY;
		}
		
		/**自定义皮肤请实现IWindowSkin接口 */
		protected getThemeSkin():IGYSkin
		{var s = this;
			return GYSprite.skinTheme.GetWindowSkin();
		}
		protected oper(e:egret.TouchEvent):void
		{var s = this;
			if(e.currentTarget == s.closeBtn)
			{
				s.hide();
			}
		}
		public show(pr:IGYContainer):void
		{var s = this;
			if((<any>s.parent) != pr)
				pr.addElement(this);
		}
		public hide():void
		{var s = this;
			if(s.parent)
				(<any>s.parent).removeElement(this);
		}

		public get closeBtn():GYButton
		{var s = this;
			return s._skin.closeBtn;
		}
		/**窗体是否可拖动*/
		public get canDrag():boolean
		{var s = this;
			return s._canDrag;
		}

		public set canDrag(value:boolean)
		{var s = this;
			if(s._canDrag == value)return;
			if(s._canDrag)
				s._skin.backgoundImage.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, s.dragDown);
			s._canDrag = value;
			if(s._canDrag)
				s._skin.backgoundImage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, s.dragDown);
		}
		public setBackgound(b:egret.BitmapData):void
		{var s = this;
			s._skin.backgoundImage.bitmapData = b;
		}

		public get backgoundImage():GYScaleSprite
		{var s = this;
			return s._skin.backgoundImage;
		}
		public setIcon(val:egret.Texture):void
		{var s = this;
			(s._skin as IWindowSkin).setIcon(val);
		}
		public setTitle(val:string):void
		{var s = this;
			(s._skin as IWindowSkin).setTitle(val);	
		}
		public get icon():GYImage
		{var s = this;
			return (s._skin as IWindowSkin).icon;
		}
		public get title():GYText
		{var s = this;
			return (s._skin as IWindowSkin).title;
		}
		/**窗口拖动到s.y方向范围*/
		public get dragRange():number
		{var s = this;
			return s._dragRange;
		}

		public set dragRange(value:number)
		{var s = this;
			s._dragRange = value;
		}


	}
}